<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>智慧社区管理系统 - 首页</title>
    <!-- 引入 FontAwesome 图标库 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
    <!-- 引入 Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <!-- 引入 Chart.js 库 -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <style>
        :root {
            --primary-color: #3498db;
            --secondary-color: #2980b9;
            --success-color: #2ecc71;
            --warning-color: #f39c12;
            --danger-color: #e74c3c;
            --light-color: #ecf0f1;
            --dark-color: #34495e;
            --text-color: #333;
            --border-color: #ddd;
            --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            --transition: all 0.3s ease;
            --ai-gradient: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: 'Noto Sans SC', Arial, sans-serif;
            line-height: 1.6;
            color: var(--text-color);
            background-color: #f5f7fa;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        /* 头部样式 */
        .header {
            background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
            color: white;
            padding: 15px 0;
            text-align: center;
            box-shadow: var(--shadow);
            position: relative;
            z-index: 100;
        }

        .header h1 {
            font-weight: 500;
            margin: 0;
            font-size: 1.8rem;
        }

        /* 导航栏样式 */
        .nav {
            background-color: white;
            padding: 0;
            box-shadow: var(--shadow);
            position: sticky;
            top: 0;
            z-index: 99;
        }

        .nav ul {
            list-style-type: none;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
        }

        .nav ul li {
            position: relative;
        }

        .nav ul li a {
            text-decoration: none;
            color: var(--dark-color);
            padding: 15px 25px;
            display: block;
            font-weight: 500;
            transition: var(--transition);
        }

        .nav ul li a:hover,
        .nav ul li a.active {
            color: var(--primary-color);
            background-color: rgba(52, 152, 219, 0.1);
        }

        .nav ul li a.active:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 3px;
            background-color: var(--primary-color);
        }

        /* 主内容区样式 */
        .main-content {
            display: flex;
            margin-top: 20px;
        }

        .sidebar {
            width: 250px;
            background-color: white;
            border-radius: 8px;
            box-shadow: var(--shadow);
            padding: 15px;
            margin-right: 20px;
            height: fit-content;
        }

        .sidebar h3 {
            color: var(--dark-color);
            margin-bottom: 15px;
            padding-bottom: 10px;
            border-bottom: 1px solid var(--border-color);
        }

        .sidebar-menu {
            list-style: none;
        }

        .sidebar-menu li {
            margin-bottom: 5px;
        }

        .sidebar-menu a {
            display: block;
            padding: 10px;
            color: var(--text-color);
            text-decoration: none;
            border-radius: 4px;
            transition: var(--transition);
        }

        .sidebar-menu a:hover,
        .sidebar-menu a.active {
            background-color: rgba(52, 152, 219, 0.1);
            color: var(--primary-color);
        }

        .sidebar-menu i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
        }

        .content {
            flex: 1;
        }

        /* 卡片样式 */
        .card {
            background-color: white;
            border-radius: 8px;
            box-shadow: var(--shadow);
            padding: 20px;
            margin-bottom: 20px;
        }

        .card-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 1px solid var(--border-color);
        }

        .card-header h2 {
            color: var(--dark-color);
            font-size: 1.4rem;
            margin: 0;
        }

        /* 表单样式 */
        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: var(--dark-color);
        }

        .form-control {
            width: 100%;
            padding: 10px 15px;
            border: 1px solid var(--border-color);
            border-radius: 4px;
            font-size: 1rem;
            transition: var(--transition);
        }

        .form-control:focus {
            border-color: var(--primary-color);
            outline: none;
            box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
        }

        textarea.form-control {
            min-height: 120px;
            resize: vertical;
        }

        select.form-control {
            appearance: none;
            background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
            background-repeat: no-repeat;
            background-position: right 10px center;
            background-size: 1em;
        }

        /* 按钮样式 */
        .btn {
            display: inline-block;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            font-size: 1rem;
            font-weight: 500;
            cursor: pointer;
            transition: var(--transition);
            text-align: center;
        }

        .btn-primary {
            background-color: var(--primary-color);
            color: white;
        }

        .btn-primary:hover {
            background-color: var(--secondary-color);
        }

        .btn-success {
            background-color: var(--success-color);
            color: white;
        }

        .btn-success:hover {
            background-color: #27ae60;
        }

        .btn-warning {
            background-color: var(--warning-color);
            color: white;
        }

        .btn-warning:hover {
            background-color: #e67e22;
        }

        .btn-danger {
            background-color: var(--danger-color);
            color: white;
        }

        .btn-danger:hover {
            background-color: #c0392b;
        }

        .btn-outline {
            background-color: transparent;
            border: 1px solid var(--border-color);
            color: var(--text-color);
        }

        .btn-outline:hover {
            background-color: var(--light-color);
        }

        .btn-sm {
            padding: 5px 10px;
            font-size: 0.875rem;
        }

        .btn-icon {
            display: inline-flex;
            align-items: center;
            justify-content: center;
        }

        .btn-icon i {
            margin-right: 5px;
        }

        /* 表格样式 */
        .table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }

        .table th,
        .table td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid var(--border-color);
        }

        .table th {
            background-color: var(--light-color);
            color: var(--dark-color);
            font-weight: 500;
        }

        .table tr:hover {
            background-color: rgba(52, 152, 219, 0.05);
        }

        .table .actions {
            white-space: nowrap;
        }

        /* 状态标签 */
        .badge {
            display: inline-block;
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 0.75rem;
            font-weight: 500;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .badge-primary {
            background-color: rgba(52, 152, 219, 0.1);
            color: var(--primary-color);
        }

        .badge-success {
            background-color: rgba(46, 204, 113, 0.1);
            color: var(--success-color);
        }

        .badge-warning {
            background-color: rgba(243, 156, 18, 0.1);
            color: var(--warning-color);
        }

        .badge-danger {
            background-color: rgba(231, 76, 60, 0.1);
            color: var(--danger-color);
        }

        /* 仪表盘统计卡片 */
        .stats-container {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
            gap: 20px;
            margin-bottom: 20px;
        }

        .stat-card {
            background-color: white;
            border-radius: 8px;
            box-shadow: var(--shadow);
            padding: 20px;
            display: flex;
            align-items: center;
        }

        .stat-icon {
            width: 60px;
            height: 60px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 15px;
            font-size: 1.5rem;
            color: white;
        }

        .stat-icon.primary {
            background-color: var(--primary-color);
        }

        .stat-icon.success {
            background-color: var(--success-color);
        }

        .stat-icon.warning {
            background-color: var(--warning-color);
        }

        .stat-icon.danger {
            background-color: var(--danger-color);
        }

        .stat-info h3 {
            font-size: 1.8rem;
            margin: 0;
            color: var(--dark-color);
        }

        .stat-info p {
            margin: 5px 0 0;
            color: #777;
        }

        /* AI功能入口卡片 */
        .ai-card {
            background: var(--ai-gradient);
            border-radius: 12px;
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
            padding: 30px;
            margin: 30px 0;
            color: white;
            position: relative;
            overflow: hidden;
            transition: all 0.4s ease;
        }

        .ai-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
        }

        .ai-card:before {
            content: "";
            position: absolute;
            top: -50%;
            right: -50%;
            width: 200px;
            height: 200px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 50%;
            z-index: 0;
        }

        .ai-card:after {
            content: "";
            position: absolute;
            bottom: -30%;
            left: -10%;
            width: 150px;
            height: 150px;
            background: rgba(255, 255, 255, 0.08);
            border-radius: 50%;
            z-index: 0;
        }

        .ai-content {
            position: relative;
            z-index: 1;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .ai-text {
            flex: 1;
            padding-right: 20px;
        }

        .ai-text h2 {
            font-size: 2rem;
            margin-bottom: 10px;
            font-weight: 600;
        }

        .ai-text p {
            font-size: 1.1rem;
            margin-bottom: 20px;
            opacity: 0.9;
            max-width: 600px;
        }

        .ai-icon {
            font-size: 6rem;
            opacity: 0.2;
            transition: all 0.3s ease;
        }

        .ai-card:hover .ai-icon {
            opacity: 0.3;
            transform: scale(1.05);
        }

        .ai-features {
            display: flex;
            flex-wrap: wrap;
            gap: 15px;
            margin-top: 20px;
        }

        .ai-feature {
            background: rgba(255, 255, 255, 0.15);
            backdrop-filter: blur(5px);
            border-radius: 8px;
            padding: 10px 15px;
            font-size: 0.9rem;
            display: flex;
            align-items: center;
        }

        .ai-feature i {
            margin-right: 8px;
            font-size: 1.2rem;
        }

        .btn-ai {
            background: white;
            color: #6a11cb;
            padding: 12px 25px;
            border-radius: 50px;
            font-weight: 600;
            font-size: 1.1rem;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
            transition: all 0.3s ease;
            border: none;
            display: inline-flex;
            align-items: center;
        }

        .btn-ai:hover {
            background: #f8f9fa;
            transform: translateY(-3px);
            box-shadow: 0 7px 20px rgba(0, 0, 0, 0.25);
            color: #6a11cb;
        }

        .btn-ai i {
            margin-left: 8px;
            transition: transform 0.3s ease;
        }

        .btn-ai:hover i {
            transform: translateX(5px);
        }

        /* 移动端模拟 */
        .mobile-preview {
            width: 320px;
            border: 12px solid #222;
            border-radius: 30px;
            padding: 15px;
            background-color: #f5f5f5;
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
            margin: 0 auto;
        }

        .mobile-header {
            background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
            color: white;
            padding: 15px;
            border-radius: 10px 10px 0 0;
            text-align: center;
            margin-bottom: 15px;
        }

        .mobile-nav {
            display: flex;
            justify-content: space-around;
            padding: 10px 0;
            background-color: white;
            border-radius: 0 0 10px 10px;
            box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.05);
        }

        .mobile-nav-item {
            text-align: center;
            color: #777;
            font-size: 0.8rem;
        }

        .mobile-nav-item.active {
            color: var(--primary-color);
        }

        .mobile-nav-item i {
            display: block;
            font-size: 1.2rem;
            margin-bottom: 5px;
        }

        /* 响应式设计 */
        @media (max-width: 992px) {
            .main-content {
                flex-direction: column;
            }

            .sidebar {
                width: 100%;
                margin-right: 0;
                margin-bottom: 20px;
            }

            .nav ul {
                flex-wrap: wrap;
            }

            .nav ul li {
                margin-bottom: 5px;
            }

            .ai-content {
                flex-direction: column;
                text-align: center;
            }

            .ai-text {
                padding-right: 0;
                margin-bottom: 20px;
            }

            .ai-icon {
                margin-top: 20px;
            }
        }

        @media (max-width: 768px) {
            .stats-container {
                grid-template-columns: 1fr 1fr;
            }

            .ai-card {
                padding: 20px;
            }

            .ai-text h2 {
                font-size: 1.7rem;
            }

            .ai-icon {
                font-size: 4rem;
            }

            .mobile-preview {
                width: 280px;
            }
        }

        @media (max-width: 576px) {
            .stats-container {
                grid-template-columns: 1fr;
            }

            .nav ul li a {
                padding: 10px 15px;
                font-size: 0.9rem;
            }

            .ai-text h2 {
                font-size: 1.5rem;
            }

            .ai-text p {
                font-size: 1rem;
            }

            .ai-features {
                flex-direction: column;
            }
        }

        /* 动画效果 */
        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(20px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .animate-fade {
            animation: fadeIn 0.5s ease forwards;
        }

        /* 选项卡样式 */
        .tabs {
            display: flex;
            border-bottom: 1px solid var(--border-color);
            margin-bottom: 20px;
        }

        .tab {
            padding: 10px 20px;
            cursor: pointer;
            border-bottom: 3px solid transparent;
            transition: var(--transition);
        }

        .tab:hover {
            color: var(--primary-color);
        }

        .tab.active {
            color: var(--primary-color);
            border-bottom-color: var(--primary-color);
            font-weight: 500;
        }

        .tab-content {
            display: none;
        }

        .tab-content.active {
            display: block;
        }

        /* 模态框样式 */
        .modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0, 0, 0, 0.4);
        }

        .modal-content {
            background-color: #fefefe;
            margin: 10% auto;
            padding: 20px;
            border: 1px solid #888;
            width: 80%;
            max-width: 600px;
            border-radius: 8px;
        }

        .close {
            color: #aaa;
            float: right;
            font-size: 28px;
            font-weight: bold;
        }

        .close:hover,
        .close:focus {
            color: black;
            text-decoration: none;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div class="header">
        <h1><i class="fas fa-building"></i> 智慧社区管理系统</h1>
    </div>
    <div class="nav">
        <ul>
            <li><a href="shoye.html" class="active"><i class="fas fa-home"></i> 首页</a></li>
            <li><a href="resident.html"><i class="fas fa-users"></i> 住户管理</a></li>
            <li><a href="property.html"><i class="fas fa-home"></i> 房产管理</a></li>
            <li><a href="repair.html"><i class="fas fa-tools"></i> 报修维护</a></li>
            <li><a href="fee.html"><i class="fas fa-money-bill-wave"></i> 费用管理</a></li>
            <li><a href="security.html"><i class="fas fa-shield-alt"></i> 社区安防</a></li>
            <li><a href="index.html"><i class="fas fa-sign-out-alt"></i> 退出登录</a></li>
        </ul>
    </div>
    <div class="container">
        <!-- 仪表盘 -->
        <div id="dashboard" class="section">
            <div class="stats-container">
                <div class="stat-card animate-fade" style="animation-delay: 0.1s;">
                    <div class="stat-icon primary">
                        <i class="fas fa-users"></i>
                    </div>
                    <div class="stat-info">
                        <h3>1,248</h3>
                        <p>总住户数</p>
                    </div>
                </div>
                <div class="stat-card animate-fade" style="animation-delay: 0.2s;">
                    <div class="stat-icon success">
                        <i class="fas fa-check-circle"></i>
                    </div>
                    <div class="stat-info">
                        <h3>92%</h3>
                        <p>物业费缴纳率</p>
                    </div>
                </div>
                <div class="stat-card animate-fade" style="animation-delay: 0.3s;">
                    <div class="stat-icon warning">
                        <i class="fas fa-tools"></i>
                    </div>
                    <div class="stat-info">
                        <h3>18</h3>
                        <p>待处理报修</p>
                    </div>
                </div>
                <div class="stat-card animate-fade" style="animation-delay: 0.4s;">
                    <div class="stat-icon danger">
                        <i class="fas fa-exclamation-triangle"></i>
                    </div>
                    <div class="stat-info">
                        <h3>3</h3>
                        <p>紧急事件</p>
                    </div>
                </div>
            </div>

            <!-- AI功能入口卡片 -->
            <div class="ai-card animate-fade" style="animation-delay: 0.5s;">
                <div class="ai-content">
                    <div class="ai-text">
                        <h2><i class="fas fa-robot"></i> 智慧社区AI功能</h2>
                        <p>体验下一代社区管理技术：智能安防、AI客服、能源优化和智能停车管理等创新功能，让社区管理更高效、更安全、更智能。</p>

                        <div class="ai-features">
                            <div class="ai-feature">
                                <i class="fas fa-shield-alt"></i>
                                <span>智能安防监控</span>
                            </div>
                            <div class="ai-feature">
                                <i class="fas fa-comments"></i>
                                <span>24/7 AI客服</span>
                            </div>
                            <div class="ai-feature">
                                <i class="fas fa-car"></i>
                                <span>智能停车管理</span>
                            </div>
                            <div class="ai-feature">
                                <i class="fas fa-bolt"></i>
                                <span>能源优化系统</span>
                            </div>
                        </div>

                        <a href="ai.html" class="btn-ai">
                            立即体验AI功能 <i class="fas fa-arrow-right"></i>
                        </a>
                    </div>
                    <div class="ai-icon">
                        <i class="fas fa-brain"></i>
                    </div>
                </div>
            </div>

            <div class="card">
                <div class="card-header">
                    <h2><i class="fas fa-bell"></i>社区公告</h2>
                    <a href="#" class="btn btn-outline" onclick="showAddModal()">添加公告</a>
                </div>
                <div class="table-responsive">
                    <table class="table">
                        <thead>
                            <tr>
                                <th>标题</th>
                                <th>发布时间</th>
                                <th>分类</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody id="announcementTableBody">
                            <tr>
                                <td>关于春节期间社区安全注意事项</td>
                                <td>2024-02-01</td>
                                <td><span class="badge badge-primary">安全通知</span></td>
                                <td><span id="status-1" class="badge badge-primary">未读</span></td>
                                <td class="actions">
                                    <a href="#" class="btn btn-sm btn-outline" onclick="showModal('关于春节期间社区安全注意事项', '2024-02-01', '安全通知', '春节期间，请各位住户注意用火、用电、用气安全，关好门窗，避免发生盗窃和火灾事故。', 'status-1')">查看</a>
                                </td>
                            </tr>
                            <tr>
                                <td>2024年第二季度物业费收缴通知</td>
                                <td>2024-03-01</td>
                                <td><span class="badge badge-warning">缴费通知</span></td>
                                <td><span id="status-2" class="badge badge-success">已读</span></td>
                                <td class="actions">
                                    <a href="#" class="btn btn-sm btn-outline" onclick="showModal('2024年第二季度物业费收缴通知', '2024-03-01', '缴费通知', '请各位住户在2024年3月31日前缴纳第二季度的物业费，感谢您的配合。', 'status-2')">查看</a>
                                </td>
                            </tr>
                            <tr>
                                <td>社区电梯维护计划通知</td>
                                <td>2024-03-10</td>
                                <td><span class="badge badge-info">设施维护通知</span></td>
                                <td><span id="status-3" class="badge badge-success">已读</span></td>
                                <td class="actions">
                                    <a href="#" class="btn btn-sm btn-outline" onclick="showModal('社区电梯维护计划通知', '2024-03-10', '设施维护通知', '为确保电梯的安全运行，将于2024年3月15日对社区电梯进行维护，预计维护时间为半天，给您带来不便，敬请谅解。', 'status-3')">查看</a>
                                </td>
                            </tr>
                            <tr>
                                <td>社区绿化改造通知</td>
                                <td>2024-03-15</td>
                                <td><span class="badge badge-secondary">社区建设通知</span></td>
                                <td><span id="status-4" class="badge badge-primary">未读</span></td>
                                <td class="actions">
                                    <a href="#" class="btn btn-sm btn-outline" onclick="showModal('社区绿化改造通知', '2024-03-15', '社区建设通知', '为提升社区环境品质，将于近期对社区绿化进行改造，改造期间可能会对您的出行造成一定影响，请您谅解。', 'status-4')">查看</a>
                                </td>
                            </tr>
                            <tr>
                                <td>社区文化活动通知</td>
                                <td>2024-03-20</td>
                                <td><span class="badge badge-success">活动通知</span></td>
                                <td><span id="status-5" class="badge badge-primary">未读</span></td>
                                <td class="actions">
                                    <a href="#" class="btn btn-sm btn-outline" onclick="showModal('社区文化活动通知', '2024-03-20', '活动通知', '社区将于2024年3月25日举办一场文化活动，欢迎各位住户积极参与。', 'status-5')">查看</a>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="card">
                <div class="card-header">
                    <h2><i class="fas fa-chart-line"></i> 社区数据统计</h2>
                    <div>
                        <select class="form-control" id="timeRangeSelector" style="width: auto; display: inline-block;">
                            <option value="7">最近7天</option>
                            <option value="30">最近30天</option>
                            <option value="90">最近90天</option>
                        </select>
                    </div>
                </div>
                <div>
                    <canvas id="communityChart" width="400" height="200"></canvas>
                </div>
            </div>
        </div>
    </div>

    <!-- 模态框 -->
    <div id="myModal" class="modal">
        <div class="modal-content">
            <span class="close">&times;</span>
            <h2 id="modalTitle"></h2>
            <p><strong>发布时间：</strong><span id="modalPublishTime"></span></p>
            <p><strong>分类：</strong><span id="modalCategory"></span></p>
            <!-- 删除状态显示 -->
            <!-- <p><strong>状态：</strong><span id="modalStatus"></span></p> -->
            <p><strong>详细内容：</strong><span id="modalContent"></span></p>
        </div>
    </div>

    <!-- 添加公告模态框 -->
    <div id="addAnnouncementModal" class="modal">
        <div class="modal-content">
            <span class="close" onclick="closeAddModal()">&times;</span>
            <h2>添加公告</h2>
            <form id="addAnnouncementForm">
                <div class="form-group">
                    <label for="addTitle">标题</label>
                    <input type="text" class="form-control" id="addTitle" required>
                </div>
                <div class="form-group">
                    <label for="addPublishTime">发布时间</label>
                    <input type="date" class="form-control" id="addPublishTime" required>
                </div>
                <div class="form-group">
                    <label for="addCategory">分类</label>
                    <select class="form-control" id="addCategory" required>
                        <option value="安全通知">安全通知</option>
                        <option value="缴费通知">缴费通知</option>
                        <option value="设施维护通知">设施维护通知</option>
                        <option value="社区建设通知">社区建设通知</option>
                        <option value="活动通知">活动通知</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="addContent">详细内容</label>
                    <textarea class="form-control" id="addContent" required></textarea>
                </div>
                <button type="submit" class="btn btn-primary">添加</button>
            </form>
        </div>
    </div>

    <script>
        // 获取canvas元素和时间范围选择器
        const ctx = document.getElementById('communityChart').getContext('2d');
        const timeRangeSelector = document.getElementById('timeRangeSelector');

        // 模拟不同时间范围的数据
        const data7Days = {
            labels: ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5', 'Day 6', 'Day 7'],
            datasets: [{
                label: '社区数据',
                data: [12, 19, 3, 5, 2, 3, 10],
                backgroundColor: 'rgba(52, 152, 219, 0.2)',
                borderColor: 'rgba(52, 152, 219, 1)',
                borderWidth: 1
            }]
        };

        const data30Days = {
            labels: Array.from({ length: 30 }, (_, i) => `Day ${i + 1}`),
            datasets: [{
                label: '社区数据',
                data: Array.from({ length: 30 }, () => Math.floor(Math.random() * 20)),
                backgroundColor: 'rgba(52, 152, 219, 0.2)',
                borderColor: 'rgba(52, 152, 219, 1)',
                borderWidth: 1
            }]
        };

        const data90Days = {
            labels: Array.from({ length: 90 }, (_, i) => `Day ${i + 1}`),
            datasets: [{
                label: '社区数据',
                data: Array.from({ length: 90 }, () => Math.floor(Math.random() * 20)),
                backgroundColor: 'rgba(52, 152, 219, 0.2)',
                borderColor: 'rgba(52, 152, 219, 1)',
                borderWidth: 1
            }]
        };

        // 初始图表
        let myChart = new Chart(ctx, {
            type: 'bar',
            data: data7Days,
            options: {
                scales: {
                    y: {
                        beginAtZero: true
                    }
                }
            }
        });

        // 监听时间范围选择器的变化
        timeRangeSelector.addEventListener('change', function () {
            const selectedValue = this.value;
            let newData;

            if (selectedValue === '7') {
                newData = data7Days;
            } else if (selectedValue === '30') {
                newData = data30Days;
            } else if (selectedValue === '90') {
                newData = data90Days;
            }

            // 更新图表数据
            myChart.data = newData;
            myChart.update();
        });

        // 模态框相关代码
        const modal = document.getElementById('myModal');
        const closeBtn = document.getElementsByClassName('close')[0];

        function showModal(title, publishTime, category, content, statusId) {
            document.getElementById('modalTitle').textContent = title;
            document.getElementById('modalPublishTime').textContent = publishTime;
            document.getElementById('modalCategory').textContent = category;
            document.getElementById('modalContent').textContent = content;
            modal.style.display = "block";

            // 将状态更新为已读
            const statusElement = document.getElementById(statusId);
            if (statusElement && statusElement.textContent === '未读') {
                statusElement.textContent = '已读';
                statusElement.classList.remove('badge-primary');
                statusElement.classList.add('badge-success');
            }
        }

        closeBtn.onclick = function () {
            modal.style.display = "none";
        }

        window.onclick = function (event) {
            if (event.target == modal) {
                modal.style.display = "none";
            }
        }

        // 添加公告模态框相关代码
        const addAnnouncementModal = document.getElementById('addAnnouncementModal');
        const addAnnouncementForm = document.getElementById('addAnnouncementForm');
        const announcementTableBody = document.getElementById('announcementTableBody');

        function showAddModal() {
            addAnnouncementModal.style.display = "block";
        }

        function closeAddModal() {
            addAnnouncementModal.style.display = "none";
        }

        addAnnouncementForm.addEventListener('submit', function (e) {
            e.preventDefault();

            const title = document.getElementById('addTitle').value;
            const publishTime = document.getElementById('addPublishTime').value;
            const category = document.getElementById('addCategory').value;
            const content = document.getElementById('addContent').value;

            const newRow = document.createElement('tr');
            const newStatusId = `status-${announcementTableBody.children.length + 1}`;
            newRow.innerHTML = `
                <td>${title}</td>
                <td>${publishTime}</td>
                <td><span class="badge badge-primary">${category}</span></td>
                <td><span id="${newStatusId}" class="badge badge-primary">未读</span></td>
                <td class="actions">
                    <a href="#" class="btn btn-sm btn-outline" onclick="showModal('${title}', '${publishTime}', '${category}', '${content}', '${newStatusId}')">查看</a>
                </td>
            `;

            announcementTableBody.appendChild(newRow);
            closeAddModal();
            addAnnouncementForm.reset();
        });
    </script>
</body>

</html>